import axios from '@ohos/axios'
import configs from '../config/config'
import foodCategories from '../define/foodCategories'

class FoodCategoryModel {
  baseUrl: string = configs.domain + 'api/'

  getCategories(type: number): Promise<foodCategories[]> {

    return new Promise((resolve, reject) => {
      axios.get(this.baseUrl + "labaicai/food_categories?type=" + type)
        .then((rsp) => {
          if (rsp.status === 200) {
            resolve(rsp.data.data)
          } else {
            reject("查询失败")
          }
        })
        .catch(err => {
          console.log("test  , get Error :", err)
          reject("查询失败")
        })
    })
  }
}

const foodCategoryModel = new FoodCategoryModel()

export default foodCategoryModel as FoodCategoryModel